// import { useStore } from 'vuex';
// import Cookies from 'js-cookie';
// import { useRoute } from 'vue-router';
// import { reactive } from '@vue/reactivity';
// import { onMounted } from '@vue/runtime-core';
import { apiService } from '../../api/apiService';
import { getRepairForStaff, getRepairForUser, addRepair, getOneRepair, geRepairReview, putRepairdetail, getDevicebyuuid } from '../../api/server';
import { showSuccess } from '../../util/MessageDeal';
import { selfI18n } from '@/i18n';
export function getRepairDataSetup () {
    // 员工查询
    const getRepairDataForStaff = (params) => {
        return new Promise((resolve, reject) => {
            apiService({
                api: getRepairForStaff,
                param: { ...params },
                // param: {
                //     administrator: administrator,
                //     company: company,
                //     content: content,
                //     manufacturecode: manufacturecode,
                //     n: n, // 必填
                //     name: name,
                //     p: p, // 必填
                //     phone: phone,
                //     repairid: repairid,
                //     repairtimeend: repairtimeend,
                //     repairtimestart: repairtimestart,
                //     status: status, // 必填
                //     username: username // 必填

                // },
                success: (data) => {
                    resolve(data);
                },
                fail: (data) => {
                    resolve(data);
                },
                error: (err) => {
                    reject(err);
                }
            });
        });
    };
    // 用户查询
    const getRepairDataForUser = (params) => {
        return new Promise((resolve, reject) => {
            apiService({
                api: getRepairForUser,
                param: { ...params },
                // param: {
                //     administrator: administrator,
                //     company: company,
                //     content: content,
                //     manufacturecode: manufacturecode,
                //     n: n, // 必填
                //     name: name,
                //     p: p, // 必填
                //     phone: phone,
                //     repairid: repairid,
                //     repairtimeend: repairtimeend,
                //     repairtimestart: repairtimestart,
                //     status: status, // 必填
                //     username: username // 必填

                // },
                success: (data) => {
                    resolve(data);
                },
                fail: (data) => {
                    resolve(data);
                },
                error: (err) => {
                    reject(err);
                }
            });
        });
    };
    const addNewRepair = (param, callback) => {
        apiService({
            api: addRepair,
            param: { ...param },
            success: (data) => {
                console.log(data.value);
                showSuccess(selfI18n('wp_Created_successfully'));
                callback && callback(data.value);
            }
        });
    };
    const getRepairDetail = (repairid, username) => {
        return new Promise((resolve, reject) => {
            apiService({
                api: getOneRepair,
                param: {
                    repairid: repairid,
                    username: username
                },
                success: (data) => {
                    resolve(data);
                },
                fail: (data) => {
                    resolve(data);
                },
                error: (err) => {
                    reject(err);
                }
            });
        });
    };
    // 查询报修评价
    const getRepairReviews = (repairid, username) => {
        return new Promise((resolve, reject) => {
            apiService({
                api: geRepairReview,
                param: {
                    repairid: repairid,
                    username: username

                },
                success: (data) => {
                    resolve(data);
                },
                fail: (data) => {
                    resolve(data);
                },
                error: (err) => {
                    reject(err);
                }
            });
        });
    };
    const editrepairdetail = (param, callback) => {
        apiService({
            api: putRepairdetail,
            param: { ...param },
            success: (data) => {
                // showSuccess($t('wp_Created_successfully'));
                callback && callback(data);
            }
        });
    };
    const getdevicebyuuid = (param, callback) => {
        apiService({
            api: getDevicebyuuid,
            param: { ...param },
            success: (data) => {
                // showSuccess($t('wp_Created_successfully'));
                callback && callback(data);
            }
        });
    };

    return {
        getRepairDataForUser,
        getRepairDataForStaff,
        addNewRepair,
        getRepairDetail,
        getRepairReviews,
        editrepairdetail,
        getdevicebyuuid
    };
}
